package com.tho.ccolor;

public class ColorHSV {
	public float h;//0-360
	public float s;//0-1.0
	public float v;//0-1.0
	public ColorHSV(float h, float s, float v) {
		super();
		this.h = h;
		this.s = s;
		this.v = v;
	}
//	if ( a > b ) {
//        hueDiff = Math.min( a - b, b - a + 360 );
//    } else {
//        hueDiff = Math.min( b - a, a - b + 360 );
//    }
	public float distance(ColorHSV other){
		float otherH = other.getH();
		double distH = 0;
		if(h > otherH){
			distH = Math.min(h - otherH, otherH - h + 360);
		}else{
			distH = Math.min(otherH - h, h - otherH + 360);
		}
		distH /= 360;		
		double distS = s - other.getS();
		double distV = v - other.getV();
		return (float) Math.sqrt(distH * distH + distS * distS + distV * distV);
	}
	
	public float getH() {
		return h;
	}
	public void setH(float h) {
		this.h = h;
	}
	public float getS() {
		return s;
	}
	public void setS(float s) {
		this.s = s;
	}
	public float getV() {
		return v;
	}
	public void setV(float v) {
		this.v = v;
	}	
	
	public String toString(){
		return h + "," + s + "," + v;
	}
}
